import {SchoolModel} from "../../../models/school/SchoolModel";

const schoolModel = new SchoolModel()
Page({

    /**
     * 页面的初始数据
     */
    data: {

        schoolList: [],


        saNameOption: [
            {
                text: "全部分类",
                value: 0
            }
        ],
        sortOption:[

            {
                text: "综合排序",
                value: 0
            },
            {
                text: "距离近",
                value: 1
            }

        ],
        saIdValue: 0,
        sortValue: 0,


        type: 2,
        current: 1,
        pageSize: 10


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        this._init(this.data.type, this.data.current, this.data.pageSize)

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    _init(type, current, pageSize) {

        const getSchool = schoolModel.getSchoolPage(type, current, pageSize)

        Promise.all([getSchool])
            .then(res => {
                let schoolList = res[0]

                let saNameOption = this.data.saNameOption

                schoolList.forEach(item => {

                    let saName = item.sa_name
                    let saId = item.sa_id

                    saNameOption.push({
                        "text": saName,
                        "value": saId
                    })

                })
                this.setData({
                    schoolList,
                    saNameOption
                })

            })

    }


})